//
//  SaleRightListView.m
//  SmallEasyLife
//
//  Created by qianfeng on 15/10/23.
//  Copyright © 2015年 GXK. All rights reserved.
//

#import "SaleRightListView.h"
#import "Masonry.h"

#import "Themes.h"
#import "SaleBACell.h"

#import "ThemeController.h"

@interface SaleRightListView ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, weak) UITableView * tableView;

@end

@implementation SaleRightListView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.tableView.delegate = self;
        self.tableView.dataSource = self;
        [self.tableView registerNib:[UINib nibWithNibName:@"SaleBACell" bundle:nil] forCellReuseIdentifier:@"BACell"];
    }
    return self;
}
- (UITableView *)tableView
{
    if (_tableView == nil) {
        UITableView * tableView = [[UITableView alloc] initWithFrame:self.frame style:UITableViewStylePlain];
        _tableView = tableView;
        [self addSubview:tableView];
        
        [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top);
            make.left.equalTo(self.mas_left);
            make.width.equalTo(self.mas_width);
            make.height.equalTo(self.mas_height);
        }];
    }
    return _tableView;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSInteger count = 0;
    if (self.dataArray) {
        count = self.dataArray.count;
        NSLog(@"count -> %lu",count);
    }
    return count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 220;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIStoryboard * storyBoard = [UIStoryboard storyboardWithName:@"DisPlayShare" bundle:nil];
    
    ThemeController * VC = [storyBoard instantiateInitialViewController];
    NSLog(@"adfasfasfsd");
    if ([self.ownerViewController isKindOfClass:[UIViewController class]]) {
        Themes * model = self.dataArray[indexPath.row];
        
        VC.webViewUrl = model.themeurl;
        
        [self.ownerViewController.navigationController pushViewController:VC animated:YES];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    SaleBACell * cell = [tableView dequeueReusableCellWithIdentifier:@"BACell"];
    
    Themes * model = self.dataArray[indexPath.row];
    //BeautifulAblumModel
    cell.model = model;
    
    
    return cell;
}
@end
